﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TokenAuthority
{
    public static class TokenProvider
    {

        private static HashSet<Token> Tokens = new HashSet<Token>();

        public static string GetToken(string ip, string user, string pass)
        {
            UserBank.ValidateUser(user, pass);
            var token = new Token(user, ip);
            Tokens.Add(token);
            return token.UID;
        }

        public static bool ValidateToken(string token, string ip)
        {
            if (Tokens.Any(x => x.UID.Equals(token) 
             && x.Metadata.ContainsKey("ip") 
             && x.Metadata["ip"].Equals(ip)))
                return true;
            return false;
        }

    }
}
